package com.study.guilivideo.etl;

public class ETLUtils {
    /**
     * 清洗视频数据
     * @param line
     * @return
     *
     * 规则：
     * 1.数据长度必须大于等于9
     * 2.将视频类别中的&两侧的空格去掉
     * 3.将关联视频用&连接
     *
     * 测试数据
     *  ZIXTmNfGnOE	nodud15	649	People & Blogs	35	10169	4.22	18	6	h_HFYtLUQUU	svaO-_9ITZo	R1npvpE9wE8	oeXwFmyMoNs	woouTmVKaV8	GzrRYATDVHo	s584NEORXUM	KMnav6UzQls	RV6M11N9dFM	h72hhVNLEKc	MkaoyPTzFjo	mLAbvR0hjKM	yv48eL5m6Oc	MCVCicYDi9E	57RXNjbRYt4	b4GxJhG6ltE	2TVeAd0H78M	pf1rnnZdv1U	VsSJWA8PtNQ	fzU20Zf-bnw
     */
    public static String etlGulivideoData(String line){
        StringBuffer sbs =new StringBuffer();
        //1.切割数据
        String[] splits = line.split("\t");
        //2.规则一
        if (splits.length<9){
            return null ;
        }
        //3,规则二
        splits[3]=splits[3].replaceAll(" ","");
        //4.规则三:判断有无相关视频
        for (int i = 0; i < splits.length; i++) {
            if (i<=8){
                if (i==splits.length-1){
                    sbs.append(splits[i]);
                }else {
                    sbs.append(splits[i]).append("\t");
                }
            }else {
                if (i==splits.length-1){
                    sbs.append(splits[i]);
                }else {
                    sbs.append(splits[i]).append("&");
                }
            }
        }
        return sbs.toString();
    }

    public static void main(String[] args) {
        //测试:有相关视频
        String result = etlGulivideoData("ZIXTmNfGnOE\tnodud15\t649\tPeople & Blogs\t35\t10169\t4.22\t18\t6\th_HFYtLUQUU\tsvaO-_9ITZo\tR1npvpE9wE8\toeXwFmyMoNs\twoouTmVKaV8\tGzrRYATDVHo\ts584NEORXUM\tKMnav6UzQls\tRV6M11N9dFM\th72hhVNLEKc\tMkaoyPTzFjo\tmLAbvR0hjKM\tyv48eL5m6Oc\tMCVCicYDi9E\t57RXNjbRYt4\tb4GxJhG6ltE\t2TVeAd0H78M\tpf1rnnZdv1U\tVsSJWA8PtNQ\tfzU20Zf-bnw");
        //没有相关视频
//        String result = etlGulivideoData("ZIXTmNfGnOE\tnodud15\t649\tPeople & Blogs\t35\t10169\t4.22\t18\t6");
       //长度小于9，直接返回null
//        String result = etlGulivideoData("ZIXTmNfGnOE\tnodud15\t649\tPeople & Blogs\t35\t10169\t4.22\t18");

        System.out.println(result);
    }
}
